/**
 * 
 */
package in.ac.dei.edrp.cms.daoimpl.studentregistration;

import in.ac.dei.edrp.cms.dao.studentregistration.CancelStudentRegistrationDao;
import in.ac.dei.edrp.cms.domain.studentregistration.StudentInfoGetter;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;

/**
 * @author Manpreet
 *
 */
public class CancelStudentRegistrationDaoImpl  extends SqlMapClientDaoSupport
    implements CancelStudentRegistrationDao {
    private static Logger logObj = Logger.getLogger(StudentRegistrationFormImpl.class);
    TransactionTemplate transactionTemplate = null;

    public void setTransactionTemplate(TransactionTemplate transactionTemplate) {
        this.transactionTemplate = transactionTemplate;
    }

    /**
     * Method to fetch student record
     * @param input
     * @return List
     */
	 @SuppressWarnings("unchecked")
	public List<StudentInfoGetter> getStudentDetails(
	            String input) {
	    	
	    	List<StudentInfoGetter> resultList = getSqlMapClientTemplate().queryForList("cancelRegistration.getDetails",
            		input);
					return resultList;
	    	
	    }

	 
	 
	 
	 
	 /**
	  * Method to cancel student's registration
	  * @param inputObj
	  * @return
	  */
		public String cancelRegistration(final StudentInfoGetter inputObj) {

	    	 transactionTemplate.execute(new TransactionCallback() {
	             Object savepoint = null;

	             public String doInTransaction(TransactionStatus status) {
	            	 savepoint = status.createSavepoint(); 
	            	 
	            	 try{
	            		 getSqlMapClientTemplate().update("cancelRegistration.updateTempStdProg",inputObj);
	            		 getSqlMapClientTemplate().update("cancelRegistration.updateTempStdMaster",inputObj);
	            		 getSqlMapClientTemplate().update("cancelRegistration.updateTempStdCourse",inputObj);
	            		 
	            		 getSqlMapClientTemplate().getDataSource().getConnection()
	                     .commit();
	            	 }catch (Exception e) {
	            		 logger.error(e);
	            		 status.rollbackToSavepoint(savepoint);
					}
	            	 
	            	 
	            	 
	            
	            	 
					return null;
	            	 
	             }
	    	 });
				
			
			
			return null;
	    }
	
}
